/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package trunk.view.palette;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.JPanel;
import javax.swing.JToolBar;

/**
 * Class ColorPaletteView
 * 
 * Partie graphique de la palette de couleur
 * 
 * @author LEFEVRE Michael
 * @author THOUE Jonathan
 */
public class ColorPaletteView extends JToolBar{
        
    protected List<ColorButton> colorButton = new ArrayList<ColorButton>();
    
    protected JPanel currentColor;
    /**
     * Constructeur du composant
     */
    public ColorPaletteView() {
      setPreferredSize(new Dimension(85, 90));
      setLayout(new FlowLayout(FlowLayout.LEFT));
      List<Color> listColor = Arrays.asList(
              Color.blue,
              Color.cyan,
              Color.magenta,
              Color.pink,
              Color.green,
              Color.yellow,
              Color.gray,
              Color.orange,
              Color.black);
      ColorButton button;
      for (Color color : listColor) {
           button = new ColorButton(color);
           colorButton.add(button);
           add(button);
      }
      currentColor = new JPanel();       
      currentColor.setPreferredSize(new Dimension(50, 20));
      currentColor.setBackground(Color.black);
      currentColor.setToolTipText("Votre couleur actuelle.");
      add(currentColor);
    }
    /**
     * Constructeur du composant a partir d'une liste de couleur
     */
    public ColorPaletteView(List<Color> listColor) {
      setPreferredSize(new Dimension(85, 90));
      setLayout(new FlowLayout(FlowLayout.LEFT)); 
      ColorButton button;
      for (Color color : listColor) {
           button = new ColorButton(color);
           colorButton.add(button);
           add(button);
      }
      currentColor = new JPanel();       
      currentColor.setPreferredSize(new Dimension(50, 20));
      currentColor.setBackground(Color.black);
      currentColor.setToolTipText("Votre couleur actuelle.");
      add(currentColor);
    }
    /**
     *Methode pour abonner les boutons au listenner
     * @param ctrl - listenner du composant
     */ 
    public void setColorPaletteCtrl(ColorPaletteCtrl ctrl){
        for (ColorButton button : colorButton) {
            button.addActionListener(ctrl);
        }
    }    

    /**
     * Set CurrentColor
     * @param c - Couleur courrante
     */
    public void setCurrentColor(Color c){
       currentColor.setBackground(c);
    }
    
}
